namespace MoreLinq;

using System.Collections.Generic;

sealed class ReverseComparer<T>(IComparer<T>? underlying) : IComparer<T>
{
    readonly IComparer<T> underlying = underlying ?? Comparer<T>.Default;

    public int Compare
#if NETCOREAPP3_1_OR_GREATER
        (T? x, T? y)
#else
            (T x, T y)
#endif
    {
        var result = this.underlying.Compare(x, y);
        return result < 0 ? 1 : result > 0 ? -1 : 0;
    }
}
